'use strict';

angular.module('metalabPartnerApp').directive('metaFormCheckbox', function () {
    return {
        restrict: 'A',
        require: '?ngModel',
        scope: {
            bindData: '=metaFormCheckbox'
        },
        link: function (scope, elem) {
            elem.bind('click', function (event) {
                if (!scope.bindData) {
                    scope.bindData = [];
                }
                if (event.target.checked) {
                    scope.bindData.push(elem.val());
                } else {
                    scope.bindData.splice(scope.bindData.indexOf(elem.val()), 1);
                }
                scope.$apply();
            });
        }
    };
});
